﻿using System;
using OpenTK;

namespace Mono.Rift.Core.Graphics
{
	public class Vertex
	{
		private static Color _defaultColor = Color.create(64, 0, 0, 255);
		private static Vector3 _defaultNorm = new Vector3(1, 0, 0);

		public Vector3 Pos { get; set; }
		public Color C { get; set; }
		public float U { get; set; }
		public float V { get; set; }
		public float U2 { get; set; }
		public float V2 { get; set; }
		public Vector3 Norm { get; set; }

		public Vertex (Vector3 p, Color c, float u, float v, Vector3 n)
		{
			Pos = p;
			C = c;
			U = u;
			V = v;
			Norm = n;
			U2 = u;
			V2 = v;
		}

		public Vertex (Vector3 p, Color c = null, float u = 0, float v = 0) : this(p, c, u, v, _defaultNorm)
		{
		}

		public Vertex(float x, float y, float z, uint color, float u = 0, float v = 0)
		{
			Pos = new Vector3 (x, y, z);
			C = new Color (color);
			U = u;
			V = v;
			U2 = u;
			V2 = v;
		}

		public Vertex(float x, float y, float z, Color color, float u = 0, float v = 0)
		{
			Pos = new Vector3 (x, y, z);
			C = color;
			U = u;
			V = v;
			U2 = u;
			V2 = v;
		}

		public Vertex(float x, float y, float z) : this(x, y, z, _defaultColor, 0, 0)
		{
		}

		public Vertex(Vector3 p, Color c, float u, float v, float u2, float v2, Vector3 n)
		{
			Pos = p;
			C = c;
			U = u;
			V = v;
			U2 = u2;
			V2 = v2;
			Norm = n;
		}

		public override bool Equals (object obj)
		{
			var v = obj as Vertex;
			if (v == null) return false;
			return base.Equals (obj) && Pos == v.Pos && C == v.C && U == v.U && V == v.V;
		}

		public override int GetHashCode ()
		{
			return base.GetHashCode ();
		}
	}
}

